package com.newtouch.xcd.cms.job.handler;

import cn.hutool.core.collection.CollectionUtil;
import com.newtouch.xcd.cms.entity.Distribution;
import com.newtouch.xcd.cms.service.DistributionService;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.XxlJob;
import com.xxl.job.core.log.XxlJobLogger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class CheckDistributionJobHandler extends IJobHandler {

    @Autowired
    private DistributionService distributionService;

    @XxlJob(value = "CheckDistributionJobHandler")
    @Override
    public ReturnT<String> execute(String s) throws Exception {

        Boolean successFlag = true;

        List<Distribution> distributionList = distributionService.checkDistribution();

        if(CollectionUtil.isNotEmpty(distributionList)){

            successFlag = false;

            for (Distribution distribution : distributionList) {

                Integer distributionId = distribution.getDistributionId();
                String contactsName = distribution.getContactsName();

                XxlJobLogger.log("合同id：{}，受益人：{}", distributionId, contactsName);
            }
        }

        if (successFlag) {
            return ReturnT.SUCCESS;
        } else {
            return ReturnT.FAIL;
        }
    }
}